/*$(function() {

    $('#side-menu').metisMenu();

});*/

//Loads the correct sidebar on window load,
//collapses the sidebar on window resize.
// Sets the min-height of #page-wrapper to window size
$(function() {
    $(window).bind("load resize", function() {
        var topOffset = 50;
        var width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.width;
        if (width < 768) {
            $('div.navbar-collapse').addClass('collapse');
            topOffset = 100; // 2-row-menu
        } else {
            $('div.navbar-collapse').removeClass('collapse');
        }

        /*var height = ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1;
        height = height - topOffset;
        if (height < 1) height = 1;
        if (height > topOffset) {
            $("#page-wrapper").css("min-height", (height) + "px");
        }*/

        //add  _height adjust
        /*var _height =  ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1;
        if(width  < 768){
            _height = _height - 56 - 101;
        }else if(width  < 992){
            _height = _height - 101;
        }else{
            _height = _height - 75 - 101;
        }
        $("body .login-bg").css("height", (_height) + "px");*/

        //add t_height 
        var t_height = ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1;
        
        if(width  < 768){
            t_height = t_height - 56 - 101;
        }else{
            t_height = t_height - 75 - 101;
        }
        var c_height =  $("#login-container").outerHeight(true);
        var r_height = $("#login-row").outerHeight(true);
        if(c_height!=null && r_height!=null){
              
              t_height = (c_height > t_height) ? c_height : t_height;
              t_height = (r_height > t_height) ? r_height : t_height;
              $("body .login-bg").css("height", (t_height) + "px");
        }
        //$("body").css({ "overflow":"hidden"}); 
        //if(width< 992) $("body").css({"overflow":"auto"}); 
    });

    var url = window.location;
    // var element = $('ul.nav a').filter(function() {
    //     return this.href == url;
    // }).addClass('active').parent().parent().addClass('in').parent();
    var element = $('ul.nav a').filter(function() {
     return this.href == url;
    }).addClass('active').parent();

    while(true){
        if (element.is('li')){
            element = element.parent().addClass('in').parent();
        } else {
            break;
        }
    }
});
